package p5p4Plus;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class p5PlusMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    private String zdUid="";
    private IntWritable valueOut=new IntWritable(1);
    private Text keyOut=new Text();

    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        zdUid=context.getConfiguration().get("zduid");
    }

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line=value.toString();
        String[] fields=line.split(",");
        String uid=fields[0];
        String iid=fields[1];
        String btype=fields[2];
        String itype=fields[3];
        String time=fields[4];


        //验证该条数据对应的ID是否和传进来的uid匹配，如果匹配则取出该条记录对应的商品编号
        if(uid.equals(zdUid)){
            keyOut.set(iid);
            context.write(keyOut,valueOut);
        }
    }
}
